home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86b.arc / FWD_REF.DOC < prev    next >
Encoding:
Text File  |  1986-06-22  |  2.1 KB  |  58 lines

  1. ---FWD_REF.DOC---
  2.  
  3. Forward References
  4.  
  5. A86 allows names for a variety of program elements to be forward referenced.
  6. This means that you may use a symbol in one statement and define it later with
  7. another statement.  For example:
  8.  
  9.   JNZ TARGET
  10.    .
  11.    .
  12. TARGET:
  13.   ADD AX,10
  14.  
  15. In this example, a conditional jump is made to TARGET, a label farther down in
  16. the code.  When JNZ TARGET is seen, TARGET is undefined, so this is a forward
  17. reference.
  18.  
  19. The only types of symbols that can be forward-referenced are labels (as in the
  20. above example) and constants. You cannot forward-reference a variable name.
  21. Hence, you should declare all your variables at the top of your program.
  22.  
  23. As a general rule, it is best to restrict your forward references to assembler
  24. directives and jump ahead code, paying particular attention to avoiding them in
  25. the rest of your instruction statements.  This is easily done if you organize
  26. your source file so that the statements defining variables and constants precede
  27. your instruction statements.  Keep in mind that the fewer guesses the assembler
  28. has to make, the better job it will do.
  29.  
  30.  
  31. Forward References in Expressions
  32.  
  33. Because A86 performs its assembly in just one pass through the source code, the
  34. uses of forward references are restricted.  In particular, forward references
  35. cannot be used in expression arithmetic.  However, there is a trick you can use
  36. to work your way around almost any case where you might run into this
  37. restriction.  The trick is to move the expression evaluation down in your
  38. program so that it no longer contains a forward reference; and forward-reference
  39. the evaluation answer.  For example, suppose you have a data-structure that
  40. begins with its own length.  You first try to code it as follows:
  41.  
  42. D_RECORD:
  43.   DW BEYOND-$
  44.   .
  45.   .
  46. BEYOND:
  47.  
  48. You will get an error for the above try because your forward-reference of BEYOND
  49. appears in the expression BEYOND-$.  You can correct this by moving the
  50. expression evaluation to the end of the table:
  51.  
  52. D_RECORD:
  53.   DW  D_RECORD_LENGTH
  54.   .
  55.   .
  56. D_RECORD_LENGTH  EQU  $-D_RECORD
  57.  
  58.